When I check my url on open graph debugger and click on scrape again
https://developers.facebook.com/tools/debug/sharing/?q=https%3A%2F%2Fwww.tvsrbija.online%2Findex.php
I get an strange error
our page has meta tags in the body instead of the head. This may be because your HTML was malformed and they fell lower in the parse tree.
Please fix this in order for the tags to be usable.
But everything with my code is fine when you look into the source.
I tried scraping blank index.php file, and when i do, here is what Facebook sees
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head></html>
But there is no such code, If i go to blank index.php page of my site and check the source it is blank...
BUT, when i use index.html instead of index.php Facebook sees no code as it should with an empty index.php
Problem is my script is php and not html so i can not use html extension to fix problem. I even tried rewriting .php extension to html because I thought maybe Facebook handles it differently but with no luck.
Also I try pausing Cloudflare for couple of days and the same thing...
What can it be?
EDIT: Here you can see how Facebook sees my source code https://developers.facebook.com/tools/debug/echo/?q=https%3A%2F%2Fwww.tvsrbija.online%2Findex.php
In the provided source link, your output does not have a page head. It must have a valid head and body node to be valid html markup. You can see this in the first three lines of the response body provided by facebook:
<!DOCTYPE html>
<html><body>
<p>
Facebook is likely converting your <head> tag into a <body> tag because your source does not contain a <body>. Your index.php page should scrape like this to be correct:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body></body></html>
In the future, validate your html markup using the w3c validator to be sure it is correct:
https://validator.w3.org/
Try changing encoding to UTF8 without boom instead of just utf8. This has been a headache for many developers because utf8 adds info before file indicating file is utf8
I try to learn how to write Javascript but I have found a problem either so basic I would never think about it or so complicated that I lack the knowladge to find it.
I am Using NetbeansIDE 8.0 .
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<head>
<title>Objekt Navigator</title>
</head>
<body>
Something<br/>
<script language="javascript" type="text/javascript">
document.write("Text");
alert("Bla bla");
</script>
Else<br/>
</body>
</html>
If the compiled page is opened it will only display "Something" and "Else" but nothing of the script.
If I remove "document.write("Text");" it will show the alert but there is no wrong wording in "document.write".
I really need one (or more) pointers to understand this.
Pointer 1:
Don't use document.write. Really. It has been archaic and obsolete for at least 15 years, if not 20. Use regular DOM methods.
Whatever tutorial you found that in, choose something else.
Pointer 2: Don't use XHTML. Use the HTML5 Doctype. The XHTML one does some very weird things with JavaScript -- IF the file is being served as XHTML.
Lastly: your code works just fine for me. If this is not the exact code that you are using in your tests, look at your console.log to see if you have an error somewhere.
I've got a page I'm adding as a Web Resource in a dynamics CRM form. I've developed the code outside the iframe and it works standalone in IE (9+) and Firefox navigating directly to the resource URL. (edited)
Coming back to testing the code embedded in CRM after a days standalone development and now; none of the scripts run when loaded as part of the CRM form. I've tested this by adding small alert scripts at every stage of the javascript load (as follows), now these work in all browsers as far back as IE5, but not when loaded within an IFrame on the CRM form:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
alert("1");
</script>
<!-- etc.. -->
I've also tried creating a local page to load my page in an iframe which also works as expected:
<!DOCTYPE html>
<html>
<head>
<title>Iframe test</title>
</head>
<body style="background: Red;">
<h1>Hello, World!</h1>
<iframe width="500" height="500" src="http://server:5555/...">
</iframe>
</body>
</html>
as this issue only occurs in an IFrame I've run out of ideas for how to debug it. My best guess would be the issue is a conflict with code in the parent page but even then I'd expect my alert at the entry point of the html file would run.
I'm not sure at what point yesterday the code stopped working and don't have a backup unfortunately. I'd appreciate any speculation on why scripts would be abandoned within an IFrame, tips on any extra debugging steps I could try... or a solution =p.
Turned off "Restrict Cross-frame scripting" in the properties for the web-resource on the form which solved the issue.
Thanks for all the help though!
Have you tried adding it as a web resource rather than an iframe? There could be some xss security kicking in. Web Resource should get over that. The Web Resource also has other advantages (dependency aware etc).
I am trying to make my pages work correctly with IE 8, I found out from here: http://www.masykur.web.id/post/How-to-Make-Our-Website-to-be-Ready-for-IE8.aspx
that, my page has to be XHTML 1.0 compliant and atleast CSS 2.1 compliant, I made my page and CSS compliant with only few warnings, but still window.onload() is not firing. Does anybody encountered this problem?
here is the code snippet:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8"/>
<title>Testing</title>
<link rel="stylesheet" href="test.css" type="text/css"></link>
<script type="text/javascript" src="login.js"></script>
<script type="text/javascript" src="common.js"></script>
<script type="text/javascript">
window.onload = function()
{
// Not coming here at all on first shot
}
</script>
</head>
<body>
.
.
.
However refreshing the page seems to make it work.
Am I missing something here?
UPDATE:
One of the IE addons created this problem, after disabling its working fine. Thanks for your time and answers :)
For IE try:
window.onload = new function() { alert('hello');};
This is a pretty old thread but I found a solution that might help others.
I was adding a function to window.onload via a dynamically injected script (really to mimic an external script load for reasons which are not important in this context). As stated in this post, on the first load within IE8, the window.onload would not fire, but all subsequent calls would.
I found out that if I put this in the HTML file as an internal script, it would work everytime:
var windowOnload = window.onload || function() {};
window.onload = function() { windowOnload(); };
All the above code does is "initializes" IE8's window.onload unobtrusively. I suspect that IE8 fails to trigger window.onload the first time if it is called from an external script as the onload event isn't attached yet to window (or in tech terms, its typeof is undefined). It seems that the first time that's what IE8 is doing: attaching onload to window without executing it properly.
The above code then becomes quite obvious: We are merely forcing IE8 to recognize the onload event. We don't care what gets executed, or what doesn't, so we simply make sure to pipe on through any existing window.onload code that is already defined (just as a precaution).
It is important to have this as an internal script to the HTML (at least from my testing).
Your HTML would thus look something like this (the relevant parts):
<script type="text/javascript">
var windowOnload=window.onload||function(){};window.onload=function(){windowOnload();};
</script>
<script type="text/javascript" src="script.js">
</script>
From my testing, after clearing cache, and reloading the page, I have gotten window.onload to successfully trigger each time.
I hope this helps.
You could have an error in your JavaScript's, if that happens, any JavaScript after that will not function correctly.
Try to remove the reference to login.js and common.js and try an alert within your problematic function.
I don't have IE8 to personally test, but what does this test do?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test IE 8</title>
<script type="text/javascript">
/* <![CDATA[ */
window.onload = function(){alert('Good morning!');}
/* ]]> */
</script>
</head>
<body>
<h1>Hello</h1>
<body>
</html>
If this test works as expected, try the CDATA bit around your internal JavaScript block.
And then, if that does not work as expected, there is probably something in the external JavaScript above it that prevents your onload from firing. The previous poster mentioned this. At that point, try your error console or debugger to point the way.
onload fires after ALL your content has loaded (including external images etc). It's possible those resources are taking a long time to load on the first go (before they are cached). Another possibility is an error in your code that only affects IE as is stopping your scripts (but only the first time is odd).
If you are getting different results using Apache vs. another web server (IIS?) and comparing the end result using IE8, then the differrence must be in the content type header being sent. Get the wget utility for your platform and see the headers that are produced. If you are on Windows, then the Portable Apps version of the GUI wget is pretty nice.
The following code works for me. When I load the page in Firefox I see the alert instantly. When I first load the page in IE 8 it warns me about active content. If I allow the blocked content it asks me to confirm, which I do. Then the alert appears as expected. If this does not work for you, try IE 8 on a different computer or start eliminating code in your page to check for errors. You could do a binary search: comment out the first half of the page and see if the alert appears; if it still does not, then uncomment out the first half and comment out the second half. Repeat as needed until you've narrowed it down to the offending code. Incidentally you don't need XHTML for IE8 compliance. HTML works fine and actually has some advantages.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8"/>
<title></title>
<style type="text/css">
</style>
<script type="text/javascript">
window.onload=function() { alert('hello');};
</script>
</head>
<body>
</body>
</html>
I know this is kinda old question, but I just faced the same thing.
window.onload=function() { alert('hello');};
is treated differently than
window.onload= new function() { alert('hello');};
The keyword here is new.
My JS was terminating whenever it reaches (onload=) part until I added the word'new' before 'function'. Even though it worked fine without 'new' in my localhost, but once I put it online, it doesn't work until I add 'new'.
Old question but I had the same issue but it turned out to be another problem. My problem was that I did <script type="application/javascript"> which <IE9 does not understand or try to run even. For it to work for older browsers you still have to use text/javascript even though this isn't technically the correct type...
I'd like to use Javascript to make IE6 download a file. It'll be created on the fly using Javascript. This file doesn't exist on a webserver. Here's a small example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript">
function clicked() {
var xml = "<data>Just for testing</data>";
document.open("text/xml", "replace");
document.write(xml);
}
</script>
</head>
<body>
<input type="button" value="Download" onclick="clicked();" />
</body>
</html>
Instead of loading the xml in the browser window, I want it to cause IE6 to prompt the user where to download the data to so that it can be saved without them having to use File -> Save as. Any ideas?
For IE6 you should be able to use document.execCommand() after your document.write():
document.execCommand('SaveAs',true,'file.xml');
This is not part of any standard and will only work in IE flavor browsers.
If your data must be generated client side, then you can post it back to the server so that it can be returned as a downloadable file.
No, this is not possible. A web-browser strictly doesn't allow this, as the ability to save files to disk through JavaScript only, would be very dangerous, even if the confirmation popup shows up.
EDIT: Thanks to other answers, I found out (not surprisingly) that this behavior is possible with some versione of IE.