mateplays Posted December 26, 2020 Share Posted December 26, 2020 Hey guys. I want your help. I have a new resource that uses CEF browsers. The problem starts here, i want to use executeBrowserJavascript - and the class is not added to the div's. Code: addEventHandler("onClientBrowserDocumentReady", webBrowser, function () executeBrowserJavascript(webBrowser, "document.getElementById('holder').innerHTML = '<small style=float: left; font-size: 100%;><strong></strong></small><br/>';") executeBrowserJavascript(webBrowser, "document.getElementById('holder').innerHTML = document.getElementById('holder').innerHTML + '<div class=msg center>Beszélgetés elindítva.</div> <div style=clear: both;></div>'; window.scrollTo(0,document.body.scrollHeight);") end ) Code on CEF dev tools: <div id="holder"><small style="float:" left;="" font-size:="" 100%;=""><strong></strong></small><br><div class="msg" center="">Beszélgetés elindítva.</div> <div style="clear:" both;=""></div></div> Link to comment
Moderators Patrick Posted December 26, 2020 Moderators Share Posted December 26, 2020 (edited) Hi. I don't understand your problem at all. Can you explain it better? And send more codes. Your executeBrowserJavascript looks good, except style attributes in html. It should look like this: <div id="holder"> <small style="float: left; font-size: 100%"> <strong></strong> </small> <br> <div class="msg" center="">Beszélgetés elindítva.</div> <div style="clear: both"></div> </div> (btw I don't understand what do you want with small and strong tags either) Edited December 26, 2020 by Patrick Link to comment
mateplays Posted December 26, 2020 Author Share Posted December 26, 2020 (edited) I can't send more codes this is only what I got. If this code was great I could make more code and I would be able to finish the script. The problem is that is does not look right. The only problem I have right now is with the executeBrowserJavascript, that it does not set the class and the style properly. It does not matter how I change my code, the result is still bad for some reason... Here is the full code for chat.html from CEF window: <html> <head> <meta charset="UTF-8"> </head> <style id="theStyle">* { font-size: 95% !important; } .nocolor { font-size: 80% !important; } .right { text-align: right; float: right; background: rgba(124, 197, 118, 0.85); margin-left: 10px !important; } .center { text-align: center; float: center; background: rgba(232, 30, 67, 0.85); margin: 0 auto; } .left { text-align: left; float: left; background: rgba(89, 142, 215, 0.85); margin-right: 10px !important; } .msg { padding: 10px; margin: 10px; }</style> <body><div id="holder"><small style="float:" left;="" font-size:="" 100%;=""><strong>Username - 19:3:7</strong></small><br><div class="msg" center="">Beszélgetés elindítva.</div> <div style="clear:" both;=""></div></div></body></html> Here is the full code that I have right now (if the code was working I could finish the script...) local sx, sy = guiGetScreenSize() local adminPanelOpened = false local PMselected = 0 -- fonts local Roboto = dxCreateFont("files/Roboto.ttf", 15, false, "antialiased") local webBrowser = createBrowser(661, 515, true, false) function math.round(val) return math.ceil(val-0.5) end function openAdminPanel() if not adminPanelOpened then if getElementData(localPlayer, "acc:admin") >=1 then adminPanelOpened = true end else if getElementData(localPlayer, "acc:admin") >=1 then adminPanelOpened = false PMselected = 0 end end end addCommandHandler("apanel", openAdminPanel) function openAdminPanelRender() if adminPanelOpened then dxDrawImage(sx/2-825/2, sy/2-506/2, 661, 515, webBrowser, 0, 0, 0,tocolor(255,255,255),true) end end addEventHandler("onClientRender", getRootElement(), openAdminPanelRender) addEventHandler("onClientBrowserCreated", webBrowser, function() setDevelopmentMode(true, true) toggleBrowserDevTools(webBrowser, true) loadBrowserURL(webBrowser, "http://mta/local/files/chat.html") end ) addEventHandler("onClientBrowserDocumentReady", webBrowser, function () local time = getRealTime() local hourok = time.hour local percek = time.minute local masodpercek = time.second executeBrowserJavascript(webBrowser, "document.getElementById('theStyle').innerHTML = '* { font-size: 95% !important; } .nocolor { font-size: 80% !important; } .right { text-align: right; float: right; background: rgba(124, 197, 118, 0.85); margin-left: 10px !important; } .center { text-align: center; float: center; background: rgba(232, 30, 67, 0.85); margin: 0 auto; } .left { text-align: left; float: left; background: rgba(89, 142, 215, 0.85); margin-right: 10px !important; } .msg { padding: 10px; margin: 10px; }';") executeBrowserJavascript(webBrowser, "document.getElementById('holder').innerHTML = '<small style=float: left; font-size: 100%;><strong>Username - "..hourok..":"..percek..":"..masodpercek.."</strong></small><br/>';") executeBrowserJavascript(webBrowser, "document.getElementById('holder').innerHTML = document.getElementById('holder').innerHTML + '<div class=msg center>Beszélgetés elindítva.</div> <div style=clear: both;></div>'; window.scrollTo(0,document.body.scrollHeight);") end ) Edit: <strong> and <small> are HTML tags, I want to use them in my script. Edit 2: I know HTML and barely JS, but I don't know why my script does not set those tags correctly... Edited December 26, 2020 by mateplays Link to comment
Moderators Patrick Posted December 26, 2020 Moderators Share Posted December 26, 2020 Quote that it does not set the class and the style properly You should move <style>...</style> inside <head>. Because now it's between <head> and <body>. Link to comment
mateplays Posted December 26, 2020 Author Share Posted December 26, 2020 (edited) 17 minutes ago, Patrick said: You should move <style>...</style> inside <head>. Okay, I moved style up, but... Still not working. <html><head> <meta charset="UTF-8"> <style id="theStyle">* { font-size: 95% !important; } .nocolor { font-size: 80% !important; } .right { text-align: right; float: right; background: rgba(124, 197, 118, 0.85); margin-left: 10px !important; } .center { text-align: center; float: center; background: rgba(232, 30, 67, 0.85); margin: 0 auto; } .left { text-align: left; float: left; background: rgba(89, 142, 215, 0.85); margin-right: 10px !important; } .msg { padding: 10px; margin: 10px; }</style> </head> <body><div id="holder"><small style="float:" left;="" font-size:="" 100%;=""><strong>Username - 19:26:34</strong></small><br><div class="msg" center="">Beszélgetés elindítva.</div> <div style="clear:" both;=""></div></div></body></html> Edit: Somehow I would need to add a new apostrophe into my executeBrowserJavascript (like this: <div class='msg center'> , but I have used both of the available characters. (', ") Edit 2: If I manually edit the code in the CEF developer window, it works perfectly, so I am 1000% sure that there is a problem with my executeBrowserJavascript, but I don't know what. Edited December 26, 2020 by mateplays Link to comment
Moderators Patrick Posted December 26, 2020 Moderators Share Posted December 26, 2020 You can write more quotation mark, just write a backslash before it. local str = "something('A text with \"quotation marks\".')" Link to comment
mateplays Posted December 26, 2020 Author Share Posted December 26, 2020 (edited) You are my saviour. Thank you very much, now it works! Happy holidays. Hungarian: Köszi szépen, kellemes ünnepeket. Edited December 26, 2020 by mateplays 1 Link to comment
Moderators Patrick Posted December 26, 2020 Moderators Share Posted December 26, 2020 23 minutes ago, mateplays said: You are my saviour. Thank you very much, now it works! Happy holidays. Hungarian: Köszi szépen, kellemes ünnepeket. Nincs mit, neked is. 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now