473,778 Members | 2,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling JS function from within iframe tag

I'm new to Javascript and to html and am trying to make the following
code snippet work but it doesn't. It refuses to call the getPage()
function and I always get a 404 error. I know the code is getting as
far as the iframe section as other parts of the html code work
correctly. But
it is not executing any code within the getPage() function as some
"hello world" writes within getPage() wouldn't print.

-----------------------------------------------------------------------------------
..
..
..

<script language="javas cript" type="text/javascript">

function getPage() {
<!--
.... some code here
return pageURL;
//-->
}
</script>
</head>

<body>
<iframe src="getPage()" name="whatever" width=100% height=600
frameborder="0" scrolling="yes" > </iframe>
..
..
..
-------------------------------------------------------------------------------

Can anyone help what the syntax error is here, or what I am trying
to do is not possible? Thanks and please no flames.

Dec 2 '05
13 6714
web.dev wrote:
Secondly, I do agree with you. Perhaps what I said was a little harsh.
It's not erroneous, however it is inefficient for you to place html
comment tags there. [...]

<script type = "text/javascript">
<!--
...javascript code...
//-->
</script>


It is hardly inefficient (9 bytes more or less hardly count), but it is
erroneous, at least error-prone. It is assuming that either markup parsers
are broken, not considering the content of the `script' element to be CDATA
(in HTML) or PCDATA (in XHTML), or that script engines are broken, ignoring
the operators `<', `!', and `--' if they are used in the first line of
source code and/or in that order without whitespace between them.
PointedEars
Dec 3 '05 #11
ukrbend wrote:
Here's another solution, better?

<script>
var pageURL = getPage();
document.write( "<iframe src=\"",pageURL ,"\""," width=100%
height=600 frameborder=\"0 \" scrolling=\"yes \"> ","</iframe>");
</script>


No. In what way do you consider that to be better than RobG's suggestion?
The above is not even Valid HTML.
PointedEars
Dec 3 '05 #12
RobG wrote:
VK wrote:
RobG wrote:
One technique is to write the iframe tag using script, so scriptless
browsers will not see the iframe element at all, e.g.

<script type="text/javascript">
document.write(
'<iframe src="somepage.h tml" name="whatever" width="100%"',
' height=600 frameborder="0" scrolling="yes" ><\/iframe>'
);
</script>

For what it worth to mention Netscape 4.x had (has) "JavaScript
entities" one could use for attribute values. Sometimes I'm wondering
why this very useful shortcut for document.write did not go...


I don't see much point in referring to proprietary extensions in dead
browsers.


IBTD. Netscape 4.x is very much alive, and Netscape 4.8 (1998) is quite
stable. Development and support has discontinued, but it is still used
on a considerable number of computers. For example, it is on machines
of universities' computer centers (although Mozilla Suite and Firefox
are winning bits every nanosecond :)), and some private users prefer slim
Netscape 4 Communicator instead of Firefox and Thunderbird or Mozilla
Suite.
Regardless, the advice would have been the same: depending on
script support to provide essential information for the tag to
be useful is a bad idea.


If Netscape 4.x did not have the Run-Length bug (I have not yet tested if it
is still in 4.8 which was considered a bugfix release of 4.79), client-side
scripting would indeed turn out to be useful here as NN4 does not support
the `iframe' element (that goes for my NN4.8/Linux as well), it supports
`<ilayer>...</ilayer>' IIRC.
PointedEars
Dec 3 '05 #13
ukrbend wrote:
Here's another solution, better?

<script>
The type attribute is required:

<script type="text/javascript">

var pageURL = getPage();
For truly robust code, a check should be made to ensure that getPage()
was available and actually returned something useful:

e.g.
var pageURL
if ( 'function' == typeof getPage
&& (pageURL = getPage()) // Note assignment '='
&& 'string' == typeof pageURL )
{
// use pageURL
}

document.write( "<iframe src=\"",pageURL ,"\""," width=100%


For typical use, the extra global variable can be removed and the test
simplified provided it is tested thoroughly:

if( 'function' == typeof getPage ){
document.write( '<iframe src="' + getPage() + '"'
+ ...
}

Attribute values should always be quoted (as advised previously):

"By default, SGML requires that all attribute values be delimited
using either double quotation marks (ASCII decimal 34) or single
quotation marks (ASCII decimal 39)...

"In certain cases [in HTML], authors may specify the value of an
attribute without any quotation marks. The attribute value may only
contain letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal
45), periods (ASCII decimal 46), underscores (ASCII decimal 95), and
colons (ASCII decimal 58). We recommend using quotation marks even
when it is possible to eliminate them."

<URL: http://www.w3.org/TR/html401/intro/sgmltut.html#h-3.2.2 >

An attribute value that has a percentage character '%' *must* be quoted.

I prefer to use double quotes inside single quotes rather than escaping
double inside double:

<script type="text/javascript">
if ( 'function' == typeof getPage ) {
document.write(
'<iframe src="' + getPage() + '"'
+ ' name="whatever" width="100%" height="600"'
+ ' frameborder="0" scrolling="yes" > </iframe>'
);
}
</script>
--
Rob
Dec 3 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1743
by: Dennis M. Marks | last post by:
I have a function that displays a list extracted from a table using document.write. In the displayed list I want to have a link that will call the same function but display the list in reverse. Click HERE to reverse A B C When HERE is clicked the page will redisplay as
4
3638
by: nec | last post by:
Hi, I'm having trouble calling a function thats located in a iFrame from the parent. Shortly, i can't figure out the location in DOM. In IE it works fine with a simple line of window.contens.alerter('wassa?'), but it doesnt, of course work in Firefox (0.8). I've tried document.getElementById('contens').alerter('wassa?') and
4
9518
by: coolsti | last post by:
I am aware of the setInterval and setTimeout functions for Javascript, but I can't seem to find an example that lets me do what I need to. I have a script that needs to wait until a certain condition is met. In this case, the condition is that an iframe has been reloaded completely. I do this by examining a hidden document variable in the iframe, and when it has changed from "" to "1" is the signal for me that the iframe is loaded. (if...
9
3290
by: Ragnorack67 | last post by:
.... <div id=work>hello</div> .... <IFRAME id="thisframe" src="./something.htm"></IFRAME> <script>
2
4557
by: Randell D. | last post by:
Folks, I have got this working before, in part with some help from this ng but I never really understood how I got it working... and last time, I was using it via a popup window as opposed to an IFRAME. I've got several months of javascript under my belt and can resolve most things without errors in my Mozilla Javascript Console, but this one just does not do it for me. This is the picture:
5
4643
by: mike | last post by:
If I have a document like: <script> function mike_test() {alert('hi');} </script> <iframe src="blank.html" id="my_iframe1"> </iframe> and in blank.html I have:
4
5324
by: Aaron Gray | last post by:
How do I call a function within an iframe from the container main document ? Many thanks in advance, Aaron
1
1638
by: Hocco | last post by:
Hello Everyone, Please help the novice in java scripting. I'm trying to call changeSection (x, y) function from the iframe. Basically I have my code and my iframe tag in index.html. Then I click on the menu button and it loads an iframe with the name art.html. I have a function that defines which page the user is currently on and writes the name of it. Here what I have in index.html <script type="text/javascript"> function...
0
1509
by: johnw182 | last post by:
Ok, I have a asp.net project. Everything works great. HOWEVER, this project was made to be called from within a frame or iframe. When being used within the iframe the user gets a blank frame when clicking certian buttons. Here is the code for the iframe. <iframe src="http://www.website.com/?cid=A195E1A9-A5D7-4046-89A4-1C00D4F81E35" id="frameName" frameborder="0" width="550" height="750"></iFrame> Here are the steps taken to reproduce.
0
9629
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9465
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10127
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10068
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2863
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.