Can I control the page based on content in iframe? - javascript

I'm using colorbox to "pop up" user profile when someone clicks on the profile link. The profile is loaded in iframe, because I would like them to be able to click couple of links inside and keep it in same popup. The problem occurs when user's session has timed out, because if the popup is opened it shows login page within the popup.
I'm wondering what I can do to control "outer" page based on what is returned in colorbox iframe. I'd like to redirect the entire page to login page not just the content of colorbox iframe. Is there a way to do this with javascript?
Please let me know if I did not describe the problem well enough.

Just paste this inside the <header> of your login page:
<script type="text/javascript">
if (window!=window.top) { window.top.location.href = window.location.href; }
</script>
This way you can show any page inside an iframe, except for the login page, wich will replace the entire page.
The script detects if the page is being loaded in the main window or inside an iframe, then perform a redirection to "escape" from the iframe.

you should use the following statement to redirect opening page.
window.opener.document.location.href= "/login";
If you are using ajax to load the content of iframe, than you can easily use this statement on the basis of ajax response. If you are not using ajax, than you have to send following response.
<script type="text/javascript">
window.opener.document.location.href= "/login";
</script>

Related

How can I run JavaScript after specific loads?

I created a redirect function to redirect page when user submits input to the search box. When user search something, it will redirect to some webpage.
Let's say that redirected url is "http://www.google.com" (In real, I used different URL to redirect, but just picked google.com for example)
and below is what I created.
<script>
function redirect(){
window.location = "http://www.google.com";
return false;
}
</script>
The question is----
How can I be able to run another JavaScript <script>alert("hi")</script> when http://www.google.com webpage is successfully loaded?
I'm very new to JavaScript and HTML code, so any advise would be appreciated!
Unfortunately this is not possible. After redirecting to another page, you are not able to perform any actions on it, because you don't own this page and have no permissions to do so (except you are also the owner of the other page). This is similar to iFrames. You cannot access the foreign page, because then you could manipulate it and change it's content.
In your case the only action you could perform is, to show a dialog right before redirecting to another page.

Get event outside the iframe or reload the main website from iframe

I am opening an url in iframe. That page has form to fill by user. When user fill the form, I want to reload the main website (outside the iframe) to be reload. Or if I can trigger a outside javascript function with in iframe.
I am working with ReactJs.
Ex. I have 2 Websites A and B. I am opening a specific url of site B in A using iframe. When user submit the form in ifram. I want to reload the web page of site A using javascript. When I try window.location.reload(), window.parent.location.reload(). they all reload iframe.
Have you tried using
window.location.assign(url);
and just adding the url of the original page? window.location.reload() is just refreshing the page, so if you open a new page refreshing it is still going to keep you on that page.

jQuery script keeps redirecting me from a page I'm trying to edit

I was trying to make an application in SharePoint and wanted to make it so that if you click on a button, it redirects you to a page and when that page loads I wanted it to instantly redirect the user to another page. ( I couldn't get the button to just redirect to the page I wanted on click, so that's why I tried doing it this way. ) I did this using a jQuery / JavaScript script. I'm new to making scripts so I was just testing and I ended up making this script:
<script type="text/javascript">
$(document).ready(function(){
Redirect();
});
function Redirect(){
$(document).load("url");
}
</script>
My problem is now that whenever that page loads, it just loads a blank page. But I can't get to the edit screen because it instantly redirects me to a blank page. I tried turning off JavaScript in Google Chrome but even though I was able to load the page without redirecting, I wasn't able to get to the edit page because it's in a jQuery AJAX drop down menu which obviously also doesn't work if JavaScript is turned off.
I would appreciate any help
EDIT: When I say edit screen I mean the place where I can edit the script. To do that I have to press a button on the page, but I can't do that since the page instantly redirects to a blank page.
Use the webpart maintenance page which allows you to remove and manage web parts without visiting the page, the instructions are as below.
Lets say your page is example.com/sites/default.aspx add the query string ?contents=1 to the page it will take you to the manage web parts page you can remove the script editor web part from there.
The other way is to use SharePoint designer to remove the web part this will also help you achieve the same result.

How do I redirect a pop-up to a normally loaded page?

I am trying to implement something like this:
Clicking on a link, a pop-up will be opened, something like sign-up page.
On submission, if data is unfilled, an error message will be generated.
But on successful submission, it will be redirected to the main page opened earlier in the browser.
Im using thickbox for the pop-up feature. On redirecting using the following code:
<meta http-equiv="refresh" content="1;url=http://localhost/cgi-bin/Ajax/index.pl/">
The main page is being redirected, but in the pop-up itself I want the pop-up to die after successful submission and the main page gets refreshed.
I'll asume you're using the iFrame solution from the thickbox website. It looks to me that you have to set the modal=true part in the URL and use the tb_remove() function once the login is completed. The same goes for the AJAX version.
Optionally you may add modal=true to the query string (e.g.
?KeepThis=true&TB_iframe=true&height=400&width=600&modal=true) so that
closing a ThickBox will require calling the tb_remove() function from
within the ThickBox iframe (self.parent.tb_remove()). See the iframe
demo for an example, where you must click "ok" to close the ThickBox.
You should therefore just add something like this to your javascript (that you print from perl iirc).
<script type="text/javascript">
tb_remove();
</script>
<meta http-equiv="refresh" content="1;
url=http://localhost/cgi-bin/Ajax/index.pl/">
Please note that I have not tested this and I'm only referring to the documentation.

How to use onclick on a iframe tag

How to use onclick in iframe tag to call a javascript.
I basically want redirect to other page when a user clicks on a iframe.I have added the facebook like button my site which is a iframe code. So once he has clicked on the like button i want him to get redirected to a thank you page
EDIT:
i don't want to redirect the iframe but i want to redirect the main page on any interactivity with iframe. On solution is on focus or or on click on iframe i should be able to redirect. Can i at least do it.
You can't do that. Facebook's XFBML elements (like the 'Like' button) are on a different domain than your own (and only function that way); using Javascript to modify that frame isn't possible due to security restrictions.

Categories

Resources