Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the browser do when the source of iframe is javascript

When the source of an iframe is:

javascript:'';

as in:

<iframe id="SpControlFrame1" name="SpControlFrame1" src="javascript:'';" path_src="index.php?cmd=YYY" ></iframe>

What is going on? What does the src="javascript:'';" tell the browser to do?

what does the "path_src" do?

Thanks Chris

like image 517
cbrulak Avatar asked Jan 10 '09 01:01

cbrulak


People also ask

Does JavaScript work in iframe?

It is called an inline frame because to the user it is all one web page. The child iframe is a complete browsing environment within the parent frame. It can load its own JavaScript and CSS separate from the parent.

Does iframe work if JavaScript is disabled?

If a user has javascript disabled, iframes will work. An iframe tag has attributes “height” and “width,” which allows the designer great latitude with dimensions and format like 300×250 , 728×90 depending on the Ad size. Iframe tag can appear anywhere on the page and several iframes can be added if wished to.

How do I view the source of an iframe?

To see the source of an individual frame, right-click or Ctrl -click the frame and select This Frame, and then View Frame Source. Internet Explorer: From the View menu (IE 9) or the Page menu (IE 8), select Source. If the menu bar is hidden, press Alt to make it visible.

What does an iframe do?

As Tech Target explains, “an inline frame (iFrame) is a HTML element that loads another HTML page within the document. It essentially puts another webpage within the parent page. They are commonly used for advertisements, embedded videos, web analytics and interactive content.”


1 Answers

It tells the browser to display the result of executing the empty string literal. Therefore, it would just display an empty string.

You can test the effect of this by typing in javascript:'http://stackoverflow.com'; in the address bar of a normal window/tab. You'll get a white page that says "http://stackoverflow.com" and you won't actually be taken to that URL.

This is the reason that bookmarklets often wrap the code inside void() or an anonymous function that doesn't return anything to stop the browser from trying to display the result of executing the bookmarklet. For example:

javascript:void(window.open("dom_spy.html"))

Or:

javascript:(function () { window.open("dom_spy.html"); })()

If you directly use code that returns something (a new window instance in this case), the browser will end up displaying that:

javascript:window.open("dom_spy.html");

In Firefox the above will display:

[object Window]
like image 114
Ates Goral Avatar answered Nov 05 '22 15:11

Ates Goral