JavaScript parent page redirection from iframe - javascript

I need to implement parent page redirection from iframe. I know that it is impossible to do in different domains due to browsers security.
However I found that links have target attribute and tried to use it in the following way:
someLink
It works fine if I click this link manually, but I couldn't find cross-browser solution to simulate it using JavaScript.
document.getElementById('testParentRedirect').click();
This works fine in IE, however Firefox and Safari don't know click function :).
I tried to work with jQuery, but for some reason they don't simulate click event for links.
(see following post)
I couldn't find any appropriate solution on Stack Overflow.
Maybe someone could help me in it. I will appreciate it. :)

You can do this in javascript to exit a frame:
window.top.location = "http://google.com";

You can try
top.location.replace( "http://google.com" );
in javascript to "escape" from the frame.
Edit: Using replace is slightly nicer, changed my answer to use that.

Related

Javascript refresh method doesn't work in edge?

I'm currently on a project where I need the page to refresh as soon as the music ends. With chrome and fire fox this code worked perfectly.
setTimeout(location.reload.bind(location), 206000);
However this does not work in edge.
Is there another way of going around it by using javascript not meta tags as this code snippet is in an if else statement.
As #T.J.Crowder said in comments, bind method won't work with location.reload on edge, in order to get cross browsing functionality you need to avoid using it.
Try to using this one instead:
setTimeout(function(){ location.reload(); }, 206000);

Why is the javascript psuedo-protocol not working?

So, I'm trying to run on random websites, to play with the javascript psuedo-protocol.
javascript:alert("testtesttest");
And it never works. I've tried 6 websites, and I have no clue what I'm doing wrong. I've tried googling with little success. I'm using the latest version of firefox, and I have javascript enabled.
Firefox disabled it for security reasons, because people were pasting things they were told to in the address bar.
but it still works, if you trigger it from your javascript code.
And in chrome code, I found many cases, a window is initialized with this kind of protocol.
For example if you visit http://www.w3schools.com/jsref/met_win_settimeout.asp
There will be some inside windows to be opened with
javascript:"<html><body%20style='background:transparent'></body></html>"
then later on, the location.href changed to
http://www.w3schools.com/jsref/met_win_settimeout.asp
Any one knows why this kind of change happens, and why it is allowed?
Does it suggest for layer window, the location of the window can be changed to the main page?

parent.navigate only works in IE. What alternative do I have to make it work with other browsers?

I have an anchor tag that works perfectly fine in IE. Here is an example (less some additional parameters I've omitted for clarity)
Add
Unfortunately it would appear that parent.navigate does not work in other browsers such as chrome. The error I receive is: Uncaught TypeError: Object [object global] has no method 'navigate'
I've searched online for an alternative cross-browser solution but haven't been able to successfully make anything else work. I've tried window.location, window.location.href but nothing seems to be working.
Any ideas? Thanks!
UPDATE: This anchor tag resides in an iframe (which is also part of wizard.aspx). What the link ultimately does is updates something within the frame. But regardless, all I'm looking for is an alternative to parent.navigate so it will work in other browsers besides IE. And I've already researched window.location and window.location.href found in other stack overflow articles but they obviously don't work hence why I posted a question.
FINAL UPDATE: Working code.
Add
window.location.href = 'URL';
is the standard implementation for changing the current window's location.
.navigate does not work in all browsers.
Try
Add

Popup without user action?

How is this site triggering its popup while bypassing Chrome's pop-up blocker?
http://undertexter.se/
I thought pop-up blockers only allowed window.open if it was triggered by a user action but that's not the case here so how are they doing it?
OUTDATED
Origin resources and fiddles do not work anymore.
I figured out that there is an popup opening in chrome if you visit the Website first time (empty cache) and click somewhere on the document.
After a refresh and a click on it again nothing will happen if cache wasn't removed.
So lets start the game of reverse engineering...
Took the script from
http://undertexter.se/ and startet refuscation.
After a few steps I got the following code and I think this is not planned by browser manufactures to support something like this.
Now I wish you a lot of luck to use that for your own but I think it's evil.
Look on js fiddle for the result:
Its the reverse of:
http://www.wigetmedia.com/tags/undertexter.se.js
http://jsfiddle.net/W9BdS/
Tested on my own server, This opens up http://google.com in a new (standalone) window in Chromium 28 on Ubuntu 12.04. Adblock is active.
<script type="text/javascript">
document.addEventListener('click', function() {
window.open('http://google.com','...','width=1080 height=640')
})
</script>
try this using JQuery
$('#yourCotrolId').on('click', function() {
window.open('yourLink','...','width=1080 height=640')
});
window.open is blocked by modern browsers when called not in a click event handler.
I faced this myself while using Rails' format.js responses and wrote a small plugin that makes showing JS popups as simple as calling window.open():
Popup("<div>Hello world</div>").show('up')
You could use the .trigger method for simulating an user action:
Click
$('a').trigger('click');
.trigger() can not be used to mimc such native browser events, you can use .simulate() from simulate.js to mimic such events.
include simulate.js in your file and use,
$('a').simulate('click');

Site makes web browser suddenly stop and turn off in some IE browsers

the site link is http://www.kosfan.com (korean site)
in some web browser (IE 7 and 8), the site suddenly stop and turn off in not only main pages but also other pages.
i have tried to find the reason why it happens, but i cannot.
i thought that possible reasons are javascript error, onload(ready) function and ajax-load something like that.
is there any one who can solve this problem? help me!
thanks :)
I've had similar issues with IE and JQuery - it is definitely bug of the IE browser. You need to go debug the code and find where the crash happens. In my case it was a problem of accessing an element by id in JQuery way. When I replaced $("#id") for document.getElementById it stopped crashing :-)

Categories