适用于Firefox,但不适用于IE [英] Works in Firefox, but not in IE

查看:104
本文介绍了适用于Firefox,但不适用于IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助,


我的课程作业今天到期,我已经完成了除了一个

小部分。

教师希望我们从其他地方导入一个脚本,并且因为某些原因我决定让它变得比它需要的更复杂。


我想要做的是当用户离开页面时创建一个弹出窗口

(我知道弹出窗口很糟糕,但它们是课程的一部分)

显示导入的脚本。它在firefox中完美运行,但IE

显示除脚本之外的所有内容。


我完全失去了原因,希望有人可以对此有所了解

对我来说:


(使用

onUnload =" closeWin()从body标签调用closeWin() ")


//从其他地方导入脚本。

函数closeWin(){

closeWindow = window.open (","" closeWin",

" toolbar = no,resizable = no,width = 500,height = 225,scro llbar = no,left = 250,top = 200" )

closeWindow.document.write("< html>< head>< title> An Imported

Script< \ / title>< \ / head>< body>< table align =''center''>< tr>< td colspan =''2''

align =''center''> < p>以下是导入的脚本< \ / p>< script

src =''external.js''language =''JavaScript''

type =''text / javascript''> importedScript()< \ / script>< p

align =''center''>< font face ='' arial''size ='' - 2''>这个免费脚本提供了

by< \ / font>< br>< font face =''arial,helvetica''size = '' - 2''>< a

href =''http://javascriptkit.com''> JavaScript

Kit< / a>< \ /字体>< \ / p为H.< \ / TD>< \ / TR>< \ /表>< \ /体>< \ / HTML>")

}


函数importedScript(){

//过山车脚本 - 由JavaScriptKit提供200多个免费脚本
这里!


var fs = 1

var direction =" right"

function rollertext(whichone ){

var thetext = whichone

for(i = 0; i< thetext.length; i ++){

document.write(thetext .charAt(i).fontsize(fs))


if(fs< 7&& direction ==" r ight")

fs ++

else if(fs == 7){

direction =" left"

fs--

}

if if(fs == 1){

direction =" right"

fs ++

}

else if(fs> 1&& direction ==" left")

fs -


}

}

//将以下文字更改为您的赢家

rollertext(" Life is喜欢坐过山车。紧紧抓住!

}

Please help,

My class assignment is due today and I am all finished except for one
small portion.

The instructor wants us to import a script from somewhere else, and for
some reason I deceided to make it more complicated than it needs to be.

What I am trying to do is create a popup when the user leaves the page
( I know pop-ups are bad, but they are a part of the course) that
displays the imported script. It works perfectly in firefox, but IE
displays everything except the script.

I am a total loss at why, hopefully someone can shed some light on this
for me:

(the closeWin() is called from the body tag using
onUnload="closeWin()")

// Import a script from somewhere else.
function closeWin() {
closeWindow = window.open("","closeWin",
"toolbar=no,resizable=no,width=500,height=225,scro llbar=no,left=250,top=200")
closeWindow.document.write("<html><head><title>An Imported
Script<\/title><\/head><body><table align=''center''><tr><td colspan=''2''
align=''center''><p>The following is an imported script<\/p><script
src=''external.js'' language=''JavaScript''
type=''text/javascript''>importedScript()<\/script><p
align=''center''><font face=''arial'' size=''-2''>This free script provided
by<\/font><br><font face=''arial, helvetica'' size=''-2''><a
href=''http://javascriptkit.com''>JavaScript
Kit</a><\/font><\/p><\/td><\/tr><\/table><\/body><\/html>")
}

function importedScript() {
//Roller Coaster Script - By JavaScriptKit Over 200+ free scripts
here!

var fs=1
var direction="right"
function rollertext(whichone){
var thetext=whichone
for (i=0;i<thetext.length;i++){
document.write(thetext.charAt(i).fontsize(fs))

if (fs<7&&direction=="right")
fs++
else if (fs==7){
direction="left"
fs--
}
else if (fs==1){
direction="right"
fs++
}
else if (fs>1&&direction=="left")
fs--

}
}
//Change below text to your won
rollertext("Life is like a roller coaster ride. Hang on tight!")
}

推荐答案

我对JavaScript有非常基本的了解(我自己更像是一个Java家伙,但你在哪里写的:


< script src =''external.js'' language =''JavaScript''

type =''text / javascript''>


文件external.js,就是那里导入的脚本应该是

存储?而不是与此代码一起?


此外,这可能是由于格式原因导致您发布此

代码,但评论立即显示在

之后,importScript()函数是单行注释,但它看起来像

它分为两行....留下在这里! ;在一条线上,

可能导致代码中断。


我相信你会让一些人比我更聪明对此表示反对,但

我只想把我的两美分扔进去。

CalgaryWebGuy写道:
I have a very rudimentary knowledge of JavaScript (I''m more of a Java
guy myself), but where you had written:

<script src=''external.js'' language=''JavaScript''
type=''text/javascript''>

The file "external.js", is that where the imported script should be
stored? Rather than along with this code?

Also, and this might be due to formatting reasons when you posted this
code, but the comment that shows up immediately after the
importedScript() function is a single line comment, but it looks like
it''s split along two lines....leaving "here!" on a line by itself,
which could be causing the code to break.

I''m sure you''ll get some people smarter than me to repsond to this, but
I just wanted to throw my two cents in.
CalgaryWebGuy wrote:
请帮忙,

我的课程作业今天到期,除了一小部分之外我都已经完成了。

教师要我们从其他地方导入脚本,并且
某些原因我决定让它变得比它需要的更复杂。

我想要做的是在用户离开页面时创建一个弹出窗口
(我知道弹出窗口是坏的,但它们是课程的一部分)
显示导入的脚本。它在firefox中完美运行,但是IE
显示除脚本之外的所有内容。

我完全不知道为什么,希望有人可以为我阐明这个
: br />
(closeWin()使用
onUnload =" closeWin()"从body标签调用

//从其他地方导入脚本。
函数closeWin(){
closeWindow = window.open(""," closeWin",
" toolbar = no,resizable = no,width = 500,height = 225 ,scro llbar = no,left = 250,top = 200")
closeWindow.document.write("< html>< head>< title>导入的
脚本< \ / title>< \ / head>< body>< table align =''center''>< tr>< td colspan =''2''
align =''center'' >< p>以下是导入的脚本< \ / p>< script
src =''external.js''language =''JavaScript''
type =''text / JavaScript的 '' > importedScript()< \ /凭证t>< p
align =''center''>< font face =''arial''size ='' - 2''>这个免费脚本由< \提供
/ font>< br>< font face =''arial,helvetica''size ='' - 2''>< a
href =''http://javascriptkit.com''> ; JavaScript
Kit< / a>< \ / font>< \ / p>< \ / td>< \ / tr>< \ / table>< \ / body>< \ / html>")


函数importedScript()//过山车脚本 - 由JavaScriptKit提供200多个免费脚本
这里!

var fs = 1
var direction =" right"
function rollertext(whichone){
var thetext = whichone
for (i = 0; i< thetext.length; i ++){
document.write(thetext.charAt(i).fontsize(fs))

if(fs< 7&&方向=="右)
fs ++
如果(fs == 7){
direction =" left"
fs--
}
如果(fs == 1){
direction =" right
fs ++
}
如果(fs> 1&& direction ==" left")
fs -

}
}
//将下面的文字更改为你的赢了
rollertext(生活就像坐过山车一样。紧紧抓住!
}
Please help,

My class assignment is due today and I am all finished except for one
small portion.

The instructor wants us to import a script from somewhere else, and for
some reason I deceided to make it more complicated than it needs to be.

What I am trying to do is create a popup when the user leaves the page
( I know pop-ups are bad, but they are a part of the course) that
displays the imported script. It works perfectly in firefox, but IE
displays everything except the script.

I am a total loss at why, hopefully someone can shed some light on this
for me:

(the closeWin() is called from the body tag using
onUnload="closeWin()")

// Import a script from somewhere else.
function closeWin() {
closeWindow = window.open("","closeWin",
"toolbar=no,resizable=no,width=500,height=225,scro llbar=no,left=250,top=200")
closeWindow.document.write("<html><head><title>An Imported
Script<\/title><\/head><body><table align=''center''><tr><td colspan=''2''
align=''center''><p>The following is an imported script<\/p><script
src=''external.js'' language=''JavaScript''
type=''text/javascript''>importedScript()<\/script><p
align=''center''><font face=''arial'' size=''-2''>This free script provided
by<\/font><br><font face=''arial, helvetica'' size=''-2''><a
href=''http://javascriptkit.com''>JavaScript
Kit</a><\/font><\/p><\/td><\/tr><\/table><\/body><\/html>")
}

function importedScript() {
//Roller Coaster Script - By JavaScriptKit Over 200+ free scripts
here!

var fs=1
var direction="right"
function rollertext(whichone){
var thetext=whichone
for (i=0;i<thetext.length;i++){
document.write(thetext.charAt(i).fontsize(fs))

if (fs<7&&direction=="right")
fs++
else if (fs==7){
direction="left"
fs--
}
else if (fs==1){
direction="right"
fs++
}
else if (fs>1&&direction=="left")
fs--

}
}
//Change below text to your won
rollertext("Life is like a roller coaster ride. Hang on tight!")
}






感谢您的回复,


导入的脚本存储在.js文件中,脚本

也是即时编写页面,因此,它正在自我修复中。

回合路。但据我所知,这应该有效,因为当它调用脚本时,它是一个完全由

closeWin()创建的新页面。功能。如果这有任何意义。


格式化问题是由于此消息的发布方式,并且正确编码



Robert Iver写道:
Thanks for the response,

The imported script is stored in the .js file, and so is the script
that is writing the page ''on the fly'' so, it is refrencing itself in a
round about way. But as far as I am aware, this should work, as when it
calls the script, it''s a new page entirely that is created by the
closeWin() function. If that makes any sense.

The formating issue is due to how this message is posted, and is coded
properly.
Robert Iver wrote:
我对JavaScript有一个非常基本的知识(我自己更像是一个Java人员),但是你写的是:

< script src =''external.js''language =''JavaScript''
type =''text / javascript''>

文件external。 js",是应该存储导入脚本的地方吗?而不是与此代码一起?

此外,这可能是由于格式原因导致您发布此代码,但注释会立即显示在
导入的脚本之后( )函数是单行注释,但它看起来像
它被分成两行......留下这里!在一条线上,这可能会导致代码中断。

我相信你会让一些比我更聪明的人对此表示反感,但是我只想把我的两美分扔进去。

CalgaryWebGuy写道:
I have a very rudimentary knowledge of JavaScript (I''m more of a Java
guy myself), but where you had written:

<script src=''external.js'' language=''JavaScript''
type=''text/javascript''>

The file "external.js", is that where the imported script should be
stored? Rather than along with this code?

Also, and this might be due to formatting reasons when you posted this
code, but the comment that shows up immediately after the
importedScript() function is a single line comment, but it looks like
it''s split along two lines....leaving "here!" on a line by itself,
which could be causing the code to break.

I''m sure you''ll get some people smarter than me to repsond to this, but
I just wanted to throw my two cents in.
CalgaryWebGuy wrote:
请帮助,

我的课程作业今天到期了,我我完成了除了一小部分。

指导员希望我们从其他地方导入一个脚本,并且由于某些原因我欺骗了它使它比它更复杂我需要做的是当用户离开页面时创建弹出窗口
(我知道弹出窗口很糟糕,但它们是课程的一部分)
显示导入的脚本。它在firefox中完美运行,但是IE
显示除脚本之外的所有内容。

我完全不知道为什么,希望有人可以为我阐明这个
: br />
(closeWin()使用
onUnload =" closeWin()"从body标签调用

//从其他地方导入脚本。
函数closeWin(){
closeWindow = window.open(""," closeWin",
" toolbar = no,resizable = no,width = 500,height = 225 ,scro llbar = no,left = 250,top = 200")
closeWindow.document.write("< html>< head>< title>导入的
脚本< \ / title>< \ / head>< body>< table align =''center''>< tr>< td colspan =''2''
align =''center'' >< p>以下是导入的脚本< \ / p>< script
src =''external.js''language =''JavaScript''
type =''text / JavaScript的 '' > importedScript()< \ /凭证t>< p
align =''center''>< font face =''arial''size ='' - 2''>这个免费脚本由< \提供
/ font>< br>< font face =''arial,helvetica''size ='' - 2''>< a
href =''http://javascriptkit.com''> ; JavaScript
Kit< / a>< \ / font>< \ / p>< \ / td>< \ / tr>< \ / table>< \ / body>< \ / html>")


函数importedScript()//过山车脚本 - 由JavaScriptKit提供200多个免费脚本
这里!

var fs = 1
var direction =" right"
function rollertext(whichone){
var thetext = whichone
for (i = 0; i< thetext.length; i ++){
document.write(thetext.charAt(i).fontsize(fs))

if(fs< 7&&方向=="右)
fs ++
如果(fs == 7){
direction =" left"
fs--
}
如果(fs == 1){
direction =" right
fs ++
}
如果(fs> 1&& direction ==" left")
fs -

}
}
//将下面的文字更改为你的赢了
rollertext(生活就像坐过山车一样。紧紧抓住!
}
Please help,

My class assignment is due today and I am all finished except for one
small portion.

The instructor wants us to import a script from somewhere else, and for
some reason I deceided to make it more complicated than it needs to be.

What I am trying to do is create a popup when the user leaves the page
( I know pop-ups are bad, but they are a part of the course) that
displays the imported script. It works perfectly in firefox, but IE
displays everything except the script.

I am a total loss at why, hopefully someone can shed some light on this
for me:

(the closeWin() is called from the body tag using
onUnload="closeWin()")

// Import a script from somewhere else.
function closeWin() {
closeWindow = window.open("","closeWin",
"toolbar=no,resizable=no,width=500,height=225,scro llbar=no,left=250,top=200")
closeWindow.document.write("<html><head><title>An Imported
Script<\/title><\/head><body><table align=''center''><tr><td colspan=''2''
align=''center''><p>The following is an imported script<\/p><script
src=''external.js'' language=''JavaScript''
type=''text/javascript''>importedScript()<\/script><p
align=''center''><font face=''arial'' size=''-2''>This free script provided
by<\/font><br><font face=''arial, helvetica'' size=''-2''><a
href=''http://javascriptkit.com''>JavaScript
Kit</a><\/font><\/p><\/td><\/tr><\/table><\/body><\/html>")
}

function importedScript() {
//Roller Coaster Script - By JavaScriptKit Over 200+ free scripts
here!

var fs=1
var direction="right"
function rollertext(whichone){
var thetext=whichone
for (i=0;i<thetext.length;i++){
document.write(thetext.charAt(i).fontsize(fs))

if (fs<7&&direction=="right")
fs++
else if (fs==7){
direction="left"
fs--
}
else if (fs==1){
direction="right"
fs++
}
else if (fs>1&&direction=="left")
fs--

}
}
//Change below text to your won
rollertext("Life is like a roller coaster ride. Hang on tight!")
}








CalgaryWebGuy写道:

CalgaryWebGuy wrote:
< script src =''external.js''language =''JavaScript''
type =''text / javascript''> importedScript()< \ /脚本>
<script src=''external.js'' language=''JavaScript''
type=''text/javascript''>importedScript()<\/script>




在上面的行中,您正在导入脚本并尝试执行

语句。那是不对的。引用外部脚本和脚本标签内的
语句执行应该保持单独

如下:


< script src =" external.js" type =" text / javascript">< / script>

< script type =" text / javascript">

importedScript();

< / script>


将上述解决方案格式化为您的作业。

不要认为FF是绝对的浏览器选择javascript。在

这个案例中,IE正确地做到了。



In the line above, you are importing a script and attempting to execute
statements. That is incorrect. Referencing an external script and
execution of statements within the script tags should be kept separate
like so:

<script src = "external.js" type = "text/javascript"></script>
<script type = "text/javascript">
importedScript();
</script>

Format the above solution into your assignment.
Don''t assume FF is the absolute browser of choice for javascript. In
this case, IE was doing it correctly.


这篇关于适用于Firefox,但不适用于IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆