Closed gagan-bansal closed 10 years ago
I think I can say with some considerable confidence that this is not caused by browserify-middleware. browserify-middleware is not the thing that is causing ids to be mapped or not mapped as global variables. If you believe otherwise, please produce a test case to demonstrate it.
Yes I might be doing something wrong, as I am new to node.js environment.
In browserify-middleware example itself, I added a div in index.html like this:
<!DOCTYPE html>
<html>
<head>
<script src="/js/entry-a.js"></script>
<script src="/js/entry-b.js"></script>
<script src="/js/file.js"></script>
<script src="/js/bundle.js"></script>
<script src="/non-browserify.js"></script>
</head>
<body>
Open the console to view results.
<div id='mydiv'>mydiv Test</div>
<script>alert(mydiv);</script>
</body>
</html>
After starting the server.js I get the alert ([object HTMLDivElement]]. Please suggest what could be the issue.
Yes, consider the following html file:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id='mydiv'>mydiv Test</div>
<script>alert(mydiv);</script>
</body>
</html>
You can open that directly in your browser (with no browserify stuff attached) and get exactly the same result.
See the article you linked for the reasoning behind this. Sadly, it will always be true that browsers have this feature, because it's now been standardized. You should however just ignore it and use docyment.getElementById('mydiv')
instead.
Oh yes, feeling embarrassed on such a silly issue. Sorry for bothering you.
Thanks for your time. Gagan
When I use browserify-middleware all DOM elements references are getting converted to global variables. If a div id is 'mydiv' that can be accessed as window.mydiv.
"DOM Element References as Global Variables" is part of html specification (http://tjvantoll.com/2012/07/19/dom-element-references-as-global-variables/).
But if I don't use browserify-middleware then elements ids are not mapped as global variables. So is there any solution so that we can avoid this mapping at browser.
Gagan