sted
11-19-2011, 01:13 AM
Hello,
I am currently trying to implement the Nokia Maps API in my website and I am having trouble dynamically outputting javascript with PHP.
Assuming that I am correct that when a browser opens a website the browser parses the html string and implements the code, including javascript scripts.
So theoretically it doesen't matter if I hardcode it in the HTML or if I "echo" it in PHP!?
This is the hardcoded html:
<div id="map"></div>
<script type="text/javascript">
nokia.maps.util.ApplicationContext.set({"appId": "*****", "authenticationToken": "*****"});
var map = new nokia.maps.map.Display(
document.getElementById("map"), {
components: [
// Behavior collection
new nokia.maps.map.component.Behavior(),
new nokia.maps.map.component.ZoomBar(),
new nokia.maps.map.component.Overview(),
new nokia.maps.map.component.TypeSelector(),
new nokia.maps.map.component.ScaleBar() ],
zoomLevel: 10,
center: [52.51, 13.4]
});
</script>
and this is the php code to echo the exact same code:
echo '<div id="map"></div>
<script type="text/javascript">
nokia.maps.util.ApplicationContext.set({"appId": "*****", "authenticationToken": "*****"});
var map = new nokia.maps.map.Display(
document.getElementById("map"), {
components: [
// Behavior collection
new nokia.maps.map.component.Behavior(),
new nokia.maps.map.component.ZoomBar(),
new nokia.maps.map.component.Overview(),
new nokia.maps.map.component.TypeSelector(),
new nokia.maps.map.component.ScaleBar() ],
zoomLevel: 10,
center: [52.51, 13.4]
});
map.removeComponent(map.getComponentById("zoom.MouseWheel"));
</script>';
This is the actual HTML Output of the php script:
<div id="map"></div>
<script type="text/javascript">
nokia.maps.util.ApplicationContext.set({"appId": "*****", "authenticationToken": "*****"});
var map = new nokia.maps.map.Display(
document.getElementById("map"), {
components: [
// Behavior collection
new nokia.maps.map.component.Behavior(),
new nokia.maps.map.component.ZoomBar(),
new nokia.maps.map.component.Overview(),
new nokia.maps.map.component.TypeSelector(),
new nokia.maps.map.component.ScaleBar() ],
zoomLevel: 10,
center: [52.51, 13.4]
});
map.removeComponent(map.getComponentById("zoom.MouseWheel"));
</script>
Adding document.write("Hello World");
to the script displayed the text "Hello World", so why isn't the rest executing?
Thanks in advance
I am currently trying to implement the Nokia Maps API in my website and I am having trouble dynamically outputting javascript with PHP.
Assuming that I am correct that when a browser opens a website the browser parses the html string and implements the code, including javascript scripts.
So theoretically it doesen't matter if I hardcode it in the HTML or if I "echo" it in PHP!?
This is the hardcoded html:
<div id="map"></div>
<script type="text/javascript">
nokia.maps.util.ApplicationContext.set({"appId": "*****", "authenticationToken": "*****"});
var map = new nokia.maps.map.Display(
document.getElementById("map"), {
components: [
// Behavior collection
new nokia.maps.map.component.Behavior(),
new nokia.maps.map.component.ZoomBar(),
new nokia.maps.map.component.Overview(),
new nokia.maps.map.component.TypeSelector(),
new nokia.maps.map.component.ScaleBar() ],
zoomLevel: 10,
center: [52.51, 13.4]
});
</script>
and this is the php code to echo the exact same code:
echo '<div id="map"></div>
<script type="text/javascript">
nokia.maps.util.ApplicationContext.set({"appId": "*****", "authenticationToken": "*****"});
var map = new nokia.maps.map.Display(
document.getElementById("map"), {
components: [
// Behavior collection
new nokia.maps.map.component.Behavior(),
new nokia.maps.map.component.ZoomBar(),
new nokia.maps.map.component.Overview(),
new nokia.maps.map.component.TypeSelector(),
new nokia.maps.map.component.ScaleBar() ],
zoomLevel: 10,
center: [52.51, 13.4]
});
map.removeComponent(map.getComponentById("zoom.MouseWheel"));
</script>';
This is the actual HTML Output of the php script:
<div id="map"></div>
<script type="text/javascript">
nokia.maps.util.ApplicationContext.set({"appId": "*****", "authenticationToken": "*****"});
var map = new nokia.maps.map.Display(
document.getElementById("map"), {
components: [
// Behavior collection
new nokia.maps.map.component.Behavior(),
new nokia.maps.map.component.ZoomBar(),
new nokia.maps.map.component.Overview(),
new nokia.maps.map.component.TypeSelector(),
new nokia.maps.map.component.ScaleBar() ],
zoomLevel: 10,
center: [52.51, 13.4]
});
map.removeComponent(map.getComponentById("zoom.MouseWheel"));
</script>
Adding document.write("Hello World");
to the script displayed the text "Hello World", so why isn't the rest executing?
Thanks in advance